﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace NumericalMethod
{
   public partial class ErrorForm : ContentPane
   {
      private StatusForm mStatus;
      private VParser parser = null;

      public ErrorForm()
      {
         InitializeComponent();
      }

      private void methodComboBox_SelectedIndexChanged(object sender, EventArgs e)
      {

      }
      public override void OnLoad()
      {
         mStatus = new StatusForm();
         parser = new VParser();
         Parent.Controls.Add(mStatus);
         methodComboBox.SelectedIndex = 0;
         mStatus.HidePanel(2);
      }
      private void button1_Click(object sender, EventArgs e)
      {
         double error = parser.Parse( realValue.Text + "-" + appxValue.Text );
         switch (methodComboBox.SelectedIndex)
         {
            case 0:
               mStatus.AppendOutput("Absolute error: " +
                   Math.Abs(error).ToString());
               break;
            case 1:
               mStatus.AppendOutput("Relative error: " +
                   Math.Abs(error / realValue.DoubleValue).ToString());
               break;
            case 2:
               mStatus.AppendOutput("Percent of relative error: " +
                   (Math.Abs(error / realValue.DoubleValue) * 100).ToString() + "%");
               break;
            default:
               throw new Exception();
         }
      }
   }
}
